package com.xana.acg.mikomiko.decor;

import android.content.Context;
import android.graphics.Rect;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;

import com.xana.acg.com.view.recycler.RecyclerV;


public class StaggeredDividerItemDecoration extends RecyclerV.ItemDecoration {
    private int space;
    private Context mCtx;

    public StaggeredDividerItemDecoration(Context ctx, int space){
        this.mCtx = ctx;
        this.space = space;
    }

    @Override
    public void getItemOffsets(@NonNull Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) {
        StaggeredGridLayoutManager.LayoutParams lp = (StaggeredGridLayoutManager.LayoutParams) view.getLayoutParams();
        int spanIndex = lp.getSpanIndex();
        if(spanIndex%2==0){
            outRect.left = space+10;
            outRect.right = space/2;
        }else{
            outRect.left = space/2;
            outRect.right = space+10;
        }
        outRect.bottom = space;
    }
}
